Peterson’s solution provides a good algorithmic description of solving the critical-section problem and illustrates some of the complexities involved in designing software that addresses the requirements of mutual exclusion, progress, and bounded waiting. Peterson's algorithm is considered a standard low-level algorithm for two-thread mutual exclusion.
1. Process P0 is initiated and has entered the Start state.
2. Process P0 after a certain instant of time, enters Critical section.
3. Since, Critical section is already occupied by Process P0, it is now time to trigger Process P1.
1. Process P1 is triggered.
2. Process P1 awaits in Start state as Critical section is already occupied by Process P0.
3. Process P0 has exited the Critical section and hence, Process P1 can now enter the Critical state.
4. Process P1 enters the Critical section, meanwhile Process P0 executes and enters the Exit state.
5. Process P1 exits the Critical section and executes to enter the Exit state and meanwhile Process P0 has completed.
6. Process P1 has completed.
1.Mutual Exclusion
The method provides mutual exclusion for sure. In entry section, the while condition involves the criteria for two variables therefore a process cannot enter in the critical section until the other process is interested and the process is the last one to update turn variable.
2.Progress
An uninterested process will never stop the other interested process from entering in the critical section. If the other process is also interested then the process will wait.
3.Bounded waiting
The interested variable mechanism failed because it was not providing bounded waiting. However, in Peterson solution, A deadlock can never happen because the process which first sets the turn variable will enter in the critical section for sure. Therefore, if a process is preempted after executing line number 4 of the entry section then it will definitely get into the critical section in its next chance.
4.Portability
This is the complete software solution and therefore it is portable on every hardware.